package com.order.itemcategoryproject.utils;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ParseUrl extends HashMap<String, String> {

    /**
     * 调用该方法获取请求路径参数的值
     *
     * @param url  路径参数
     * @param name 想要获取的参数名称
     * @return
     */
    public static String getUrl(String url, String name) {
        url += "&";
        String pattern = "(\\?|&){1}#{0,1}" + name + "=[a-zA-Z0-9]*(&{1})";
        Pattern r = Pattern.compile(pattern);
        Matcher matcher = r.matcher(url);
        if (matcher.find()) {
            return matcher.group(0).split("=")[1].replace("&", "");
        } else {
            return null;
        }
    }
}
